package backend_controller

import (
	"git.mycaigou.com/gfyx/micro-gfyx-api/infrastructure/common"
	"github.com/gin-gonic/gin"
	"net/http"
)

type BackendBaseController struct{}

func (c *BackendBaseController) Success(ctx *gin.Context, data interface{}) {
	result := gin.H{
		"success":    true,
		"message":    "操作成功",
		"error_code": 0,
		"data":       data,
	}

	ctx.JSON(http.StatusOK, result)
}

// Fail
// 失败返回数据数据
func (c *BackendBaseController) Fail(ctx *gin.Context, code int, msg string) {
	result := map[string]interface{}{
		"success":    false,
		"message":    common.WrapError(msg),
		"error_code": code,
		"data":       nil,
	}

	ctx.JSON(http.StatusOK, result)
}
